package cn.xbtop.blog.service.impl;

import cn.xbtop.blog.mapper.MusicMapper;
import cn.xbtop.blog.pojo.Music;
import cn.xbtop.blog.service.MusicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author  Mxb
 * @date  2020/4/17 16:39
 * @version 1.0
 */
@Service
public class MusicServiceImpl implements MusicService{

    @Resource
    private MusicMapper musicMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return musicMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Music music) {
        return musicMapper.insert(music);
    }

    @Override
    public Music selectByPrimaryKey(Integer id) {
        return musicMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(Music music) {
        return musicMapper.updateByPrimaryKey(music);
    }

    /**
     * 查询所有音乐
     * @return
     */
    @Override
    public List<Music> findAll() {
        return musicMapper.findAll();
    }

    /**
     * 启用
     * @param id
     */
    @Override
    public void enable(Integer id) {
        Music music = musicMapper.selectByPrimaryKey(id);
        music.setEnable(1);
        musicMapper.updateByPrimaryKey(music);
    }

    /**
     * 弃用
     * @param id
     */
    @Override
    public void disEnable(Integer id) {
        Music music = musicMapper.selectByPrimaryKey(id);
        music.setEnable(0);
        musicMapper.updateByPrimaryKey(music);
    }
}
